package cn.liyicun.cp.cpweb.controller;

import cn.hutool.captcha.AbstractCaptcha;
import cn.hutool.captcha.CaptchaUtil;
import cn.liyicun.cp.cpweb.util.CPConstant;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.Map;

@Controller
@RequestMapping(value = {"/user"})
//旅游者
public class TouristController extends BaseController {

    @Value("${cp.default.account}")
    private String account;

    @RequestMapping(value = "/register")
    public String register(Map<String, Object> map) {
        return "user/register";
    }

    @RequestMapping(value = "/login")
    public String login(Map<String, Object> map) {
        map.put("account", account);

        map.put("now", new Date());
        return "user/login";
    }

    @RequestMapping(value = "/captcha")
    public void captcha(HttpServletResponse response, HttpServletRequest request) throws IOException {


        //定义图形验证码的长、宽、验证码字符数、干扰线宽度
        AbstractCaptcha captcha = CaptchaUtil.createLineCaptcha(90, 50, 4, 155);
//		ShearCaptcha captcha = new ShearCaptcha(200, 100, 4, 8);
        //图形验证码写出，可以写出到文件，也可以写出到流
        captcha.write(response.getOutputStream());
        //验证图形验证码的有效性，返回boolean值
//		captcha.verify("1234");

        setAttribute(request,  CPConstant.captcha, captcha.getCode());
//        System.out.println("--------------" + captcha.getCode());
    }


}
